package com.ruoyi.project.comp.setting.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.comp.setting.domain.CompSetting;
import com.ruoyi.project.comp.setting.service.ICompSettingService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 参赛设置Controller
 * 
 * @author ruoyi
 * @date 2025-11-02
 */
@Controller
@RequestMapping("/comp/setting")
public class CompSettingController extends BaseController
{
    private String prefix = "comp/setting";

    @Autowired
    private ICompSettingService compSettingService;

    @RequiresPermissions("comp:setting:view")
    @GetMapping()
    public String setting()
    {
        return prefix + "/setting";
    }

    /**
     * 查询参赛设置列表
     */
    @RequiresPermissions("comp:setting:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CompSetting compSetting)
    {
        startPage();
        List<CompSetting> list = compSettingService.selectCompSettingList(compSetting);
        return getDataTable(list);
    }

    /**
     * 导出参赛设置列表
     */
    @RequiresPermissions("comp:setting:export")
    @Log(title = "参赛设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CompSetting compSetting)
    {
        List<CompSetting> list = compSettingService.selectCompSettingList(compSetting);
        ExcelUtil<CompSetting> util = new ExcelUtil<CompSetting>(CompSetting.class);
        return util.exportExcel(list, "参赛设置数据");
    }

    /**
     * 新增参赛设置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存参赛设置
     */
    @RequiresPermissions("comp:setting:add")
    @Log(title = "参赛设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CompSetting compSetting)
    {
        return toAjax(compSettingService.insertCompSetting(compSetting));
    }

    /**
     * 修改参赛设置
     */
    @RequiresPermissions("comp:setting:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CompSetting compSetting = compSettingService.selectCompSettingById(id);
        if(compSetting != null){
            mmap.put("compSetting", compSetting);
            return prefix + "/edit";
        }else{
            return prefix + "/add";
        }
    }

    /**
     * 修改保存参赛设置
     */
    @RequiresPermissions("comp:setting:edit")
    @Log(title = "参赛设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CompSetting compSetting)
    {
        return toAjax(compSettingService.updateCompSetting(compSetting));
    }

    /**
     * 删除参赛设置
     */
    @RequiresPermissions("comp:setting:remove")
    @Log(title = "参赛设置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(compSettingService.deleteCompSettingByIds(ids));
    }
}
